package mylinkedlist;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * 测试双向链表
 */
@SuppressWarnings({"all"})
public class Test {

    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();

        // 测试头插法
        linkedList.addFirst(1);
        linkedList.addFirst(2);
        linkedList.addFirst(3);
        linkedList.addFirst(4);
        linkedList.addFirst(5);
        System.out.println("- 头插依次插入1 2 3 4 5后:");
        linkedList.display();

        // 测试尾插法
        linkedList.clear();
        linkedList.addLast(1);
        linkedList.addLast(2);
        linkedList.addLast(3);
        linkedList.addLast(4);
        linkedList.addLast(5);
        System.out.println("\n- 清空链表后, 尾插依次插入1 2 3 4 5后:");
        linkedList.display();

        // 测试任意位置插入
        System.out.println("\n在5位置插入99");
        linkedList.addIndex(5, 99);
        linkedList.display();
        System.out.println("\n在3位置插入99");
        linkedList.addIndex(3, 99);
        linkedList.display();
        System.out.println("\n在0位置插入99");
        linkedList.addIndex(0, 99);
        linkedList.display();

        // 测试contains
        System.out.println();
        linkedList.contains(99);
        linkedList.contains(5);
        linkedList.contains(6666);

        // 测试删除第一个key
        System.out.println("删除一个99");
        linkedList.remove(99);
        linkedList.display();
        System.out.println("\n删除一个99");
        linkedList.remove(99);
        linkedList.display();
        System.out.println("\n删除一个99");
        linkedList.remove(99);
        linkedList.display();

        // 获取此时链表的长度
        System.out.println("\n此时链表的长度为:" + linkedList.size());

        // 添加
        System.out.println("尾插法添加 5 4 3 2 1");
        linkedList.addLast(5);
        linkedList.addLast(4);
        linkedList.addLast(3);
        linkedList.addLast(2);
        linkedList.addLast(1);
        linkedList.display();

        // removeAll test
        System.out.println("\n删除所有的1");
        linkedList.removeAllKey(1);
        linkedList.display();

    }
}
